package com.ibeeking.found.auth.api.feign.fallback;

import com.ibeeking.found.auth.api.common.dto.MemberLoginDTO;
import com.ibeeking.found.auth.api.common.param.LoginMemberParam;
import com.ibeeking.found.auth.api.common.param.MemberLogoutParam;
import com.ibeeking.found.auth.api.common.query.LoginAuthQuery;
import com.ibeeking.found.auth.api.common.query.OpenIdQuery;
import com.ibeeking.found.auth.api.feign.MemberLoginClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class MemberLoginFallbackFactory implements FallbackFactory<MemberLoginClient> {
    @Override
    public MemberLoginClient create(Throwable throwable) {
        return new MemberLoginClient() {

            @Override
            public ResponseResult<MemberLoginDTO> queryLoginMember(LoginMemberParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询会员登录失败。", null);
            }

            @Override
            public ResponseResult<Boolean> logout(MemberLogoutParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "会员退出登录失败。", false);
            }

            @Override
            public ResponseResult<MemberLoginDTO> queryLoginMemberByOpenId(OpenIdQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "微信登录会员信息失败。", null);
            }

            @Override
            public ResponseResult<MemberLoginDTO> queryLoginMemberByMobileOpenId(LoginAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "微信验证码登录会员信息失败。", null);
            }
        };
    }
}
